Skip to content

Commit

Permalink
Inline jest extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
nhunzaker committed Mar 16, 2018
1 parent 474b6f0 commit 0e5dede
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 45 deletions.
44 changes: 0 additions & 44 deletions packages/microcosm/src/addons/jest-matchers.js

This file was deleted.

45 changes: 44 additions & 1 deletion packages/microcosm/test/setup.js
@@ -1,4 +1,5 @@
import '../src/addons/jest-matchers'
import { get } from 'microcosm'
import expect from 'expect'

// Make a strict-only test flag
it.dev = function(description, test) {
Expand All @@ -16,3 +17,45 @@ describe.dev = function(description, suite) {

return describe.skip(description, test)
}

expect.extend({
toHaveStatus(action, status) {
let operator = this.isNot ? 'not to' : 'to'
let pass = action.status === status

return {
pass: pass,
message: () => {
return `Expected action ${operator} be '${status}'. Instead got ${
action.status
}.`
}
}
},

toHaveState(repo, key, value) {
let operator = this.isNot ? 'not to' : 'to'
let pass = false
let actual = get(repo.state, key)

if (arguments.length > 2) {
pass = JSON.stringify(actual) === JSON.stringify(value)
} else {
pass = actual !== undefined
}

// Display friendly key path
let path = [].concat(key).join('.')

return {
pass: pass,
message: () => {
return (
`Expected '${path}' in repo.state ${operator} be ${this.utils.printExpected(
value
)} ` + `but it is ${this.utils.printReceived(actual)}.`
)
}
}
}
})

0 comments on commit 0e5dede

Please sign in to comment.