Skip to content

Commit

Permalink
(refactor/test): rewrite resize test output as more BDD
Browse files Browse the repository at this point in the history
- noun / verb of describe and it for better readability
  - export it from Jest ES Module as well
  • Loading branch information
agilgur5 committed Aug 4, 2019
1 parent 58da3e5 commit 8943693
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/index.spec.js
@@ -1,4 +1,4 @@
import { describe, test, expect } from 'jest'
import { describe, it, test, expect } from 'jest'
import { mount } from 'enzyme'
import React from 'react'

Expand Down Expand Up @@ -136,20 +136,20 @@ describe('get methods return correct canvases', () => {
})

// comes after props, wrappers, and gets as it uses them all
describe('resizing works correctly', () => {
describe('canvas resizing', () => {
const wrapper = mount(<SignatureCanvas />)
const instance = wrapper.instance()
const canvas = instance.getCanvas()

test('canvas should clear on resize', () => {
it('should clear on resize', () => {
instance.fromData(dotF.data)
expect(instance.isEmpty()).toBe(false)

window.resizeTo(500, 500)
expect(instance.isEmpty()).toBe(true)
})

test('canvas should not clear when clearOnResize is false', () => {
it('should not clear when clearOnResize is false', () => {
wrapper.setProps({ clearOnResize: false })

instance.fromData(dotF.data)
Expand All @@ -160,23 +160,23 @@ describe('resizing works correctly', () => {
})

const size = { width: 100, height: 100 }
test('canvas should not change size if fixed width & height', () => {
it('should not change size if fixed width & height', () => {
wrapper.setProps({ canvasProps: size })
window.resizeTo(500, 500)

expect(canvas.width).toBe(size.width)
expect(canvas.height).toBe(size.height)
})

test('canvas should change size if no width or height', () => {
it('should change size if no width or height', () => {
wrapper.setProps({ canvasProps: {} })
window.resizeTo(500, 500)

expect(canvas.width).not.toBe(size.width)
expect(canvas.height).not.toBe(size.height)
})

test('canvas should partially change size if one of width or height', () => {
it('should partially change size if one of width or height', () => {
wrapper.setProps({ canvasProps: { width: size.width } })
window.resizeTo(500, 500)

Expand Down
2 changes: 1 addition & 1 deletion test-utils/jest-export.js
@@ -1,4 +1,4 @@
// export Jest as an ES Module (https://github.com/facebook/jest/pull/7571#issuecomment-498634094)
/* global jest */
export default jest
export const { expect, test, describe } = global
export const { expect, test, describe, it } = global

0 comments on commit 8943693

Please sign in to comment.