Mobx: useStrict does not throw error

Created on 16 May 2017  路  2Comments  路  Source: mobxjs/mobx

Using jest:

foo.test.js

import {useStrict, observable} from 'mobx';

it('should throw an exception', () => {
    expect(()=>{
        let foo = observable.map();
        useStrict(true);
        foo.set('foo','foo');
    }).toThrow(); //no exception is thrown
});

Most helpful comment

In short strict mode doesn't throw unless the observable is observed by something (autorun/reaction).
For more info see this and #798

All 2 comments

it('should throw an exception 2', () => {

    useStrict(true);

    class Foo {
        @observable foo = '';
    }

    expect(()=>{
        let foo = new Foo();
        foo.foo = 'bar';

    }).toThrow(); //no exception is thrown
});

In short strict mode doesn't throw unless the observable is observed by something (autorun/reaction).
For more info see this and #798

Was this page helpful?
0 / 5 - 0 ratings