Skip to content

Commit

Permalink
(refactor/test): export fixtures as <name>F
Browse files Browse the repository at this point in the history
- <name>F makes it more explicit that we're referencing a fixture in
  the code, similar to e.g. TypeScript I<name> for interfaces
  • Loading branch information
agilgur5 committed Nov 19, 2019
1 parent 21d8872 commit 53aad0d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions test/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { types } from 'mobx-state-tree'

export const UserStore = types.model('UserStore', {
export const UserStoreF = types.model('UserStore', {
name: 'John Doe',
age: 32
}).actions((self) => ({
Expand All @@ -9,7 +9,7 @@ export const UserStore = types.model('UserStore', {
}
}))

export const persistedData = {
export const persistedDataF = {
name: 'Persisted Name',
age: 35
}
18 changes: 9 additions & 9 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { getSnapshot } from 'mobx-state-tree'

import { persist } from '../src/index'
import { UserStore, persistedData } from './fixtures'
import { UserStoreF, persistedDataF } from './fixtures'

function getItem(key: string) {
const item = window.localStorage.getItem(key)
Expand All @@ -13,30 +13,30 @@ describe('persist', () => {
beforeEach(() => window.localStorage.clear())

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

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

it('should persist snapshot when action used', async () => {
const user = UserStore.create()
const user = UserStoreF.create()
await persist('user', user)

user.changeName('Joe') // fire action to trigger onSnapshot
expect(getItem('user')).toStrictEqual(getSnapshot(user))
})

it('should load persisted data', async () => {
window.localStorage.setItem('user', JSON.stringify(persistedData))
window.localStorage.setItem('user', JSON.stringify(persistedDataF))

const user = UserStore.create()
const user = UserStoreF.create()
await persist('user', user)
expect(getSnapshot(user)).toStrictEqual(persistedData)
expect(getSnapshot(user)).toStrictEqual(persistedDataF)
})

it('shouldn\'t jsonify', async () => {
const user = UserStore.create()
const user = UserStoreF.create()
await persist('user', user, {
jsonify: false
})
Expand All @@ -47,7 +47,7 @@ describe('persist', () => {
})

it('should whitelist', async () => {
const user = UserStore.create()
const user = UserStoreF.create()
await persist('user', user, {
whitelist: ['name']
})
Expand All @@ -59,7 +59,7 @@ describe('persist', () => {
})

it('should blacklist', async () => {
const user = UserStore.create()
const user = UserStoreF.create()
await persist('user', user, {
blacklist: ['age']
})
Expand Down

0 comments on commit 53aad0d

Please sign in to comment.