mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] store: prevent crash when selector returns null
Because `typeof null === 'object'`.
This commit is contained in:
committed by
Géry Debongnie
parent
c8d9c0b50e
commit
bc2c7edff4
@@ -49,10 +49,13 @@ describe("connecting a component to store", () => {
|
||||
});
|
||||
|
||||
test("useStore can observe primitive types and call onUpdate", async () => {
|
||||
const state = { isBoolean: false };
|
||||
const state = { isBoolean: false, nullValue: null };
|
||||
const actions = {
|
||||
setTrue({ state }) {
|
||||
state.isBoolean = true;
|
||||
},
|
||||
setNotNull({ state }) {
|
||||
state.nullValue = "ok";
|
||||
}
|
||||
};
|
||||
const store = new Store({ state, actions });
|
||||
@@ -61,8 +64,10 @@ describe("connecting a component to store", () => {
|
||||
static template = xml`
|
||||
<div>
|
||||
<span t-if="isBoolean">ok</span>
|
||||
<span t-if="nullValue !== null">not null</span>
|
||||
</div>`;
|
||||
isBoolean: boolean;
|
||||
nullValue: string;
|
||||
constructor() {
|
||||
super();
|
||||
this.isBoolean = useStore(state => state.isBoolean, {
|
||||
@@ -70,6 +75,11 @@ describe("connecting a component to store", () => {
|
||||
this.isBoolean = isBoolean;
|
||||
}
|
||||
});
|
||||
this.nullValue = useStore(state => state.nullValue, {
|
||||
onUpdate: nullValue => {
|
||||
this.nullValue = nullValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +92,10 @@ describe("connecting a component to store", () => {
|
||||
store.dispatch("setTrue");
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe("<div><span>ok</span></div>");
|
||||
|
||||
store.dispatch("setNotNull");
|
||||
await nextTick();
|
||||
expect(fixture.innerHTML).toBe("<div><span>ok</span><span>not null</span></div>");
|
||||
});
|
||||
|
||||
test("map works on the result of useStore when the resulting array changes for a bigger one", async () => {
|
||||
|
||||
Reference in New Issue
Block a user