【发布时间】:2019-09-26 06:39:21
【问题描述】:
class Store {
@computed get staticItems(): number[] {
return [1, 2, 3]
}
}
describe('mobx', () => {
it('computed static items should be same', (done) => {
let store = new Store();
let items = store.staticItems;
setTimeout(() => {
expect(items).toBe(store.staticItems);
done()
}, 500);
});
})
使用 jest 进行测试会抛出
Expected: [1, 2, 3]
Received: serializes to the same string
50 | let items = store.staticItems;
51 | setTimeout(() => {
> 52 | expect(items).toBe(store.staticItems);
这个测试通过toEqual 但失败了toBe 这意味着两个引用指向不同的对象。我错过了什么?使用 react this 会不必要地更改子组件的 props。
【问题讨论】:
标签: mobx