Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
JavaScript, Sinon.js and Chai.js Regexp literal equality Madness
chai = require 'chai'
sinon = require 'sinon'
chai.use require 'sinon-chai'
# Yup, I'm mixing style. Deal with it.
expect = chai.expect
assert = chai.assert
describe 'regexp equality', ->
describe 'using pure javascript', ->
# Irksome, but correct
it "should be false when comparing the same literals", ->
assert.notOk(/foo/ == /foo/)
describe 'sinon', ->
# Fails
it ".deepEqual with different literals", ->
assert.notOk(sinon.deepEqual(/foo/, /bar/))
it ".deepEqual with same literals", ->
assert.ok(sinon.deepEqual(/foo/, /foo/))
describe 'chai', ->
it ".notEqual with different literals", ->
assert.notEqual(/foo/, /bar/)
# Fails
it ".equal with same literals", ->
assert.equal(/foo/, /foo/)
it ".deepEqual with different literals", ->
assert.notDeepEqual(/foo/, /bar/)
it ".deepEqual with same literals", ->
assert.deepEqual(/foo/, /foo/)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment