@59naga/assert-diff 中文文档教程

发布于 6年前 浏览 22 项目主页 更新于 3年前

Greenkeeper 徽章Known Vulnerabilities

插入式替换断言以在命令行上使用 deepEqual 提供彩色差异。

这样做是为了在将对象或数组与 Mocha 进行比较时更好地区分错误。

应该在 *nix shell 上工作。

还有更多来自 https://npmjs.org/package/assert-plus 的断言

Usage

var assert = require('assert-diff')

it('diff deep equal with message', function() {
  assert.deepEqual({pow: "boom", same: true, foo: 2}, {same: true, bar: 2, pow: "bang"}, "this should fail")
})

应该给你:

Strict mode

默认情况下,一切都与 Node 的 deepEqual 一样。 使用严格模式可能是你想要的。 至少对我来说。 以下示例将通过 Node 的 deepEqual,但使用严格模式将失败:

var assert = require('assert-diff')
assert.options.strict = true

it('strict diff deep equal', function() {
  assert.deepEqual({a: 1, b: 2}, {a: true, b: "2"}, "this should fail")
})

给你:

应该 "">

Release notes

2.0.2 July 30, 2018

  • Fix usage with assert(true) style

2.0.1 July 30, 2018

  • Fix v. 2.0.0 by adding the built index.js

2.0.0 July 30, 2018

  • Migrate to ES Modules https://github.com/pihvi/assert-diff/pull/17
  • Upgrade deps
  • Thanks @59naga!

1.2.6 Apr 14, 2018

  • Add security build and badges
  • Upgrade deps

1.2.4 Oct 3, 2017

  • Upgrade deps

1.2.3 Sep 10, 2017

  • Upgrade json-diff to 0.5.2

1.2.2 Aug 20, 2017

  • Upgrade json-diff to 0.5.1

1.2.1 Aug 15, 2017

  • Add npm lock file

1.2.0 Mar 11, 2017

  • Support Node 7
  • Diff shown when loggin error object
  • Supports diff in assert.deepStrictEqual

1.1.1 Mar 11, 2017

  • fix console log example to support Node 7

1.1.0 Aug 19, 2016

  • Upgrade assert-plus 0.1.5 -> 1.0.0

1.0.1 Feb 18, 2015

  • Default behaviour back to non strict to be drop-in replacement for Node assert

1.0.0 Feb 18, 2015

  • Support assert in constructor e.g. assert(true)

0.0.x before 2015

  • Initial implementation

License

阿帕奇 2.0

Greenkeeper badgeKnown Vulnerabilities

Drop-in replacement for assert to give colored diff on command-line with deepEqual.

This exists to give better diff on error when comparing objects or arrays with Mocha.

Should work on *nix shells.

Also has more asserts from https://npmjs.org/package/assert-plus

Usage

var assert = require('assert-diff')

it('diff deep equal with message', function() {
  assert.deepEqual({pow: "boom", same: true, foo: 2}, {same: true, bar: 2, pow: "bang"}, "this should fail")
})

Should give you:

Strict mode

By default everything works as with Node's deepEqual. Using strict mode is probably what you want. At least is for me. The following example will pass with Node's deepEqual but will fail using strict mode:

var assert = require('assert-diff')
assert.options.strict = true

it('strict diff deep equal', function() {
  assert.deepEqual({a: 1, b: 2}, {a: true, b: "2"}, "this should fail")
})

Should give you:

Release notes

2.0.2 July 30, 2018

  • Fix usage with assert(true) style

2.0.1 July 30, 2018

  • Fix v. 2.0.0 by adding the built index.js

2.0.0 July 30, 2018

  • Migrate to ES Modules https://github.com/pihvi/assert-diff/pull/17
  • Upgrade deps
  • Thanks @59naga!

1.2.6 Apr 14, 2018

  • Add security build and badges
  • Upgrade deps

1.2.4 Oct 3, 2017

  • Upgrade deps

1.2.3 Sep 10, 2017

  • Upgrade json-diff to 0.5.2

1.2.2 Aug 20, 2017

  • Upgrade json-diff to 0.5.1

1.2.1 Aug 15, 2017

  • Add npm lock file

1.2.0 Mar 11, 2017

  • Support Node 7
  • Diff shown when loggin error object
  • Supports diff in assert.deepStrictEqual

1.1.1 Mar 11, 2017

  • fix console log example to support Node 7

1.1.0 Aug 19, 2016

  • Upgrade assert-plus 0.1.5 -> 1.0.0

1.0.1 Feb 18, 2015

  • Default behaviour back to non strict to be drop-in replacement for Node assert

1.0.0 Feb 18, 2015

  • Support assert in constructor e.g. assert(true)

0.0.x before 2015

  • Initial implementation

License

Apache 2.0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文