Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show object diffs in Mocha #29

Closed
rstacruz opened this issue Oct 4, 2015 · 5 comments
Closed

Show object diffs in Mocha #29

rstacruz opened this issue Oct 4, 2015 · 5 comments

Comments

@rstacruz
Copy link
Collaborator

rstacruz commented Oct 4, 2015

Here's a comparison of how Chai and Expect handles object diffs. Notice how it's very readable with the diff being shown.

pasted_image_10_5_15__3_09_am

made using this code:

describe('object comparison', function () {
  it('via chai', function () {
    var expect = require('chai').expect
    expect({a:1,b:2,c:3}).to.eq({a:1,b:2,c:4})
  })

  it('via expect', function () {
    var expect = require('../index')
    expect({a:1,b:2,c:3}).toEqual({a:1,b:2,c:4})
  })
})
@rstacruz
Copy link
Collaborator Author

rstacruz commented Oct 4, 2015

Chai throws an assertion error in this format:

{ [AssertionError: expected { a: 1, b: 2, c: 3 } to equal { a: 1, b: 2, c: 4 }]
  message: 'expected { a: 1, b: 2, c: 3 } to equal { a: 1, b: 2, c: 4 }',
  showDiff: true,
  actual: { a: 1, b: 2, c: 3 },
  expected: { a: 1, b: 2, c: 4 } }

@mjackson
Copy link
Owner

mjackson commented Oct 4, 2015

Fixed in #30

@mjackson mjackson closed this as completed Oct 4, 2015
@Anahkiasen
Copy link

Anything similar possible for Karma?

@mjackson
Copy link
Owner

mjackson commented Oct 9, 2015

Karma just runs browsers and reports the results to the console. Use mocha with karma to get these doffs in the console.

@thenickcox
Copy link

For anyone finding this via Google, karma-mocha-reporter provides this functionality, and is pretty much drop-in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants