mjackson/expect

View on GitHub
modules/__tests__/toNotMatch-test.js

Summary

Maintainability
C
1 day
Test Coverage
import expect from '../index'

describe('expect(string).toNotMatch', () => {
  it('does not throw when the actual value does not match the pattern', () => {
    expect(() => {
      expect('actual').toNotMatch(/nope/)
    }).toNotThrow()
  })

  it('throws when the actual value matches the pattern', () => {
    expect(() => {
      expect('actual').toNotMatch(/^actual$/)
    }).toThrow(/to not match/)
  })
})

describe('expect(object).toNotMatch', () => {
  it('does not throw when the actual value does not match the pattern', () => {
    expect(() => {
      expect({
        statusCode: 200,
        headers: {
          server: 'nginx web server'
        }
      }).toNotMatch({
        statusCode: 200,
        headers: {
          server: /express/
        }
      })
    }).toNotThrow()
  })

  it('throws when the actual value matches the pattern', () => {
    expect(() => {
      expect({
        statusCode: 200,
        headers: {
          server: 'express web server'
        }
      }).toNotMatch({
        statusCode: 200,
        headers: {
          server: /express/
        }
      })
    }).toThrow(/to not match/)
  })
})

describe('expect(array).toNotMatch', () => {
  it('does not throw when the array does not contain an object that matches the pattern', () => {
    const array = [
      { one: 'one' },
      { two: 'two' },
      { three: 'three' }
    ]

    expect(array).toNotMatch([ { one: /two/ } ])
  })
})