diff --git a/.travis.yml b/.travis.yml index 78f9d1f..6fd6331 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/package-lock.json b/package-lock.json index 8bc070f..0f3f43a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1117,6 +1117,15 @@ "@types/istanbul-lib-report": "*" } }, + "@types/jest": { + "version": "24.0.23", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-24.0.23.tgz", + "integrity": "sha512-L7MBvwfNpe7yVPTXLn32df/EK+AMBFAFvZrRuArGs7npEWnlziUXK+5GMIUTI4NIuwok3XibsjXCs5HxviYXjg==", + "dev": true, + "requires": { + "jest-diff": "^24.3.0" + } + }, "@types/node": { "version": "12.0.12", "resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.12.tgz", diff --git a/package.json b/package.json index 80a0cf8..b04c413 100644 --- a/package.json +++ b/package.json @@ -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" }, @@ -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", diff --git a/test/fixtures.ts b/test/fixtures.ts new file mode 100644 index 0000000..3c97e89 --- /dev/null +++ b/test/fixtures.ts @@ -0,0 +1,6 @@ +import { types } from 'mobx-state-tree' + +export const UserStore = types.model('UserStore', { + name: 'John Doe', + age: 32 +}) diff --git a/test/index.spec.ts b/test/index.spec.ts new file mode 100644 index 0000000..5b9b3e7 --- /dev/null +++ b/test/index.spec.ts @@ -0,0 +1,15 @@ +/// + +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) + }) +})