Skip to content

Instantly share code, notes, and snippets.

@morhekil
Created August 29, 2017 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morhekil/9a40e8a38840da5098ea0886b932f49f to your computer and use it in GitHub Desktop.
Save morhekil/9a40e8a38840da5098ea0886b932f49f to your computer and use it in GitHub Desktop.
mobx computed behaviour test case
import { whyRun, observable, computed } from 'mobx';
class Store {
@observable value = false;
@computed get notValue() {
whyRun();
return !this.value;
}
}
it('computes once only', () => {
const store = new Store();
console.log(store.notValue);
console.log(store.notValue);
console.log(store.notValue);
})
% jest app/bundles/admin-mojo/components/Groups/Details/__tests__/case.jsx
PASS app/bundles/admin-mojo/components/Groups/Details/__tests__/case.jsx
✓ computes once only (7ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 1.828s, estimated 2s
Ran all test suites matching "app/bundles/admin-mojo/components/Groups/Details/__tests__/case.jsx".
console.log node_modules/mobx/lib/mobx.js:3369
whyRun() can only be used if a derivation is active, or by passing an computed value / reaction explicitly. If you invoked whyRun from inside a computation; the computation is currently suspended but re-evaluating because somebody requested its value.
console.log app/bundles/admin-mojo/components/Groups/Details/__tests__/case.jsx:14
true
console.log node_modules/mobx/lib/mobx.js:3369
whyRun() can only be used if a derivation is active, or by passing an computed value / reaction explicitly. If you invoked whyRun from inside a computation; the computation is currently suspended but re-evaluating because somebody requested its value.
console.log app/bundles/admin-mojo/components/Groups/Details/__tests__/case.jsx:15
true
console.log node_modules/mobx/lib/mobx.js:3369
whyRun() can only be used if a derivation is active, or by passing an computed value / reaction explicitly. If you invoked whyRun from inside a computation; the computation is currently suspended but re-evaluating because somebody requested its value.
console.log app/bundles/admin-mojo/components/Groups/Details/__tests__/case.jsx:16
true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment