Skip to content

Commit

Permalink
feat: fixtures.mock(scenario) accepting both fixture object or name s…
Browse files Browse the repository at this point in the history
…tring
  • Loading branch information
gr2m committed Feb 11, 2018
1 parent 556342d commit 26a9dcf
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ module.exports = {
}

function get (name) {
const fixtures = require(`./scenarios/${name}/normalized-fixture.json`)
return fixtures.map(fixture => Object.assign({}, fixture))
return require(`./scenarios/${name}/normalized-fixture.json`)
}

function mock (name, additions) {
const fixtures = additions ? cloneDeep(get(name)) : get(name)
function mock (fixtures, additions) {
if (typeof fixtures === 'string') {
fixtures = get(fixtures)
}
fixtures = cloneDeep(fixtures)

if (additions) {
const applyAdditions = typeof additions === 'function'
Expand Down Expand Up @@ -56,7 +58,6 @@ function mock (name, additions) {
const requestConfig = JSON.parse(actualString)
const actual = pick(requestConfig, Object.keys(expected))
actual.headers = pick(requestConfig.headers, Object.keys(expected.headers))

error.message = `Request did not match mock ${api.pending()[0]}:\n${diffString(expected, actual)}`

delete error.config
Expand Down

0 comments on commit 26a9dcf

Please sign in to comment.