Skip to content

Commit 34c0fad

Browse files
coolhomeposvaantfu
authored
Handle non-reactive nulls (#231) (#241)
* Fixes #231 * Impl feedback * Handle undefined as well * Add unit test for undefined values * Update setup.spec.js * Apply suggestions from code review * Update test/setup.spec.js Co-authored-by: Eduardo San Martin Morote <[email protected]> Co-authored-by: Anthony Fu <[email protected]>
1 parent 530f110 commit 34c0fad

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/utils.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ export function def(obj: Object, key: string, val: any, enumerable?: boolean) {
3636
});
3737
}
3838

39-
const hasOwnProperty = Object.prototype.hasOwnProperty;
40-
export function hasOwn(obj: Object | any[], key: string): boolean {
41-
return hasOwnProperty.call(obj, key);
39+
export function hasOwn(obj: Object, key: string): boolean {
40+
return Object.hasOwnProperty.call(obj, key);
4241
}
4342

4443
export function assert(condition: any, msg: string) {

test/setup.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,30 @@ describe('setup', () => {
2020
expect(vm.a).toBe(1);
2121
});
2222

23+
it('should work with non reactive null', () => {
24+
const vm = new Vue({
25+
setup() {
26+
return {
27+
a: null,
28+
};
29+
},
30+
}).$mount();
31+
expect(vm.a).toBe(null);
32+
});
33+
34+
it('should work with non reactive undefined', () => {
35+
const vm = new Vue({
36+
setup() {
37+
return {
38+
a: undefined,
39+
b: 'foobar',
40+
};
41+
},
42+
}).$mount();
43+
expect(vm.a).toBe(undefined);
44+
expect(vm.b).toBe('foobar');
45+
});
46+
2347
it('should be overrided by data option of plain object', () => {
2448
const vm = new Vue({
2549
setup() {

0 commit comments

Comments
 (0)