1
0
Fork 0

add sinon for better testing

This commit is contained in:
Enoch Riese 2023-02-23 19:15:20 +02:00
parent ade6ad97f1
commit d1f4d875c5
6 changed files with 128 additions and 11 deletions

View file

@ -1,5 +1,6 @@
import chai from 'chai'
import { Design } from '../src/index.mjs'
import sinon from 'sinon'
const expect = chai.expect
@ -22,11 +23,6 @@ describe('Pattern', () => {
draft: ({ part }) => part,
}
describe('with runtime: true, resolveImmediately: true', () => {
it('adds the part to the current draft cycle')
it('does not add the part to subsequent draft cycles')
})
describe('with resolveImmediately: true', () => {
it('Should add the part to parts object', () => {
const design = new Design({ parts: [part1] })
@ -152,6 +148,51 @@ describe('Pattern', () => {
pattern.addPart(part3, true)
expect(pattern.config.options.opt1).to.equal(opt1)
})
describe('during drafting', () => {
it('adds the part to the draft queue', () => {
const design = new Design({ parts: [part1] })
const pattern = new design()
pattern.use({
name: 'draftTimePartPlugin',
hooks: {
postPartDraft: (pattern) => {
const newPart = {
name: 'newPartTest',
draft: ({ part }) => part,
}
pattern.addPart(newPart)
},
},
})
pattern.draft()
expect(pattern.draftQueue.contains('newPartTest')).to.be.true
})
it('drafts the part', () => {
const design = new Design({ parts: [part1] })
const pattern = new design()
const part2Draft = ({ part }) => part
const draftSpy = sinon.spy(part2Draft)
pattern.use({
name: 'draftTimePartPlugin',
hooks: {
postPartDraft: (pattern) => {
const newPart = {
name: 'newPartTest',
draft: draftSpy,
}
pattern.addPart(newPart)
},
},
})
pattern.draft()
expect(draftSpy.calledOnce).to.be.true
})
})
})
describe('with resolveImmediately: false', () => {