Skip to content

Commit

Permalink
fix: updates tests
Browse files Browse the repository at this point in the history
  • Loading branch information
msimmer committed Sep 21, 2022
1 parent 98469c9 commit f82afca
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions packages/b-ber-grammar-attributes/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ jest.mock('@canopycanopycanopy/b-ber-logger', () => ({
info: jest.fn(),
}))

afterEach(() => {
jest.clearAllMocks()
})

describe('b-ber-grammar-attributes', () => {
it('gets the file name from a path', () => {
const fileName = 'foo'
Expand Down Expand Up @@ -58,12 +62,6 @@ describe('b-ber-grammar-attributes', () => {
})

it('validates an attributes object', () => {
const spyError = jest.spyOn(log, 'error')
const spyWarn = jest.spyOn(log, 'warn')

expect(() => attributesObject('classes:foo', null)).toThrow()
expect(() => attributesObject('classes:foo', 'bogus')).toThrow()

expect(attributesObject('classes:foo', 'abstract')).toEqual({
classes: 'foo abstract chapter',
epubTypes: ' chapter',
Expand All @@ -83,9 +81,19 @@ describe('b-ber-grammar-attributes', () => {
classes: 'bodymatter chapter',
epubTypes: 'bodymatter chapter',
})
})

it('logs errors on invalid attributes object', () => {
const spyError = jest.spyOn(log, 'error')
const spyWarn = jest.spyOn(log, 'warn')

// This logs 2 errors since the test suite doesn't bail after it encounters
// the first error
expect(() => attributesObject('classes:foo', null)).toThrow()
expect(() => attributesObject('classes:foo', 'bogus')).toThrow()

expect(spyError).toHaveBeenCalledTimes(11)
expect(spyWarn).toHaveBeenCalledTimes(5)
expect(spyError).toHaveBeenCalledTimes(3)
expect(spyWarn).toHaveBeenCalledTimes(2)
})

it('converts an object literal to HTML attribtues', () => {
Expand Down

0 comments on commit f82afca

Please sign in to comment.