Skip to content

Commit

Permalink
(test): add initial test harness
Browse files Browse the repository at this point in the history
- add 1 simple test that just runs the persist function and ensures
  it doesn't persist anything if an action hasn't been used

- change test script to use jest, and move prev test to test:pub
  - (ci): change CI to run test and test:pub

- (deps): add @types/jest to devDeps
  - also add reference in spec so that the types are loaded properly
    - not sure why the reference is needed, but it would error without
      - and plain `import`ing jest or @types/jest would also error
  • Loading branch information
agilgur5 committed Nov 19, 2019
1 parent efb1cf6 commit 514715e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
language: node_js
# default is the very old 0.10.48; match local version instead
node_js: '8.9'

script: npm test
after_script: npm run test:pub
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"scripts": {
"start": "tsdx watch",
"build": "tsdx build",
"test": "npm run build && npm pack",
"test": "tsdx test",
"test:pub": "npm run build && npm pack",
"pub": "npm run build && npm publish",
"changelog": "changelog-maker"
},
Expand All @@ -39,6 +40,7 @@
"dependencies": {},
"devDependencies": {
"@agilgur5/changelog-maker": "^3.0.0",
"@types/jest": "^24.0.23",
"mobx": "^5.11.0",
"mobx-state-tree": "^3.14.0",
"tsdx": "^0.7.2",
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { types } from 'mobx-state-tree'

export const UserStore = types.model('UserStore', {
name: 'John Doe',
age: 32
})
15 changes: 15 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference types="@types/jest" />

import { persist } from '../src/index'
import { UserStore } from './fixtures'

describe('initialization', () => {
beforeEach(() => window.localStorage.clear())

it('should persist nothing if no actions are used', async () => {
const user = UserStore.create()
await persist('user', user)

expect(window.localStorage.getItem('user')).toBe(null)
})
})

0 comments on commit 514715e

Please sign in to comment.