0.1.5 • Published 5 years ago

assert-json v0.1.5

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

assert-json

Build Status codecov

An enhanced assert to diff object with a JSON file. Report line number. It should be useful to spot the error from a large JSON.

screenshot

Installation

npm install -D assert-json

Usage

const assertJSON = require("assert-json");

it("my test", () => {
  const someOutput = myFunction(`${__dirname}/testcase/my-test/input.txt`);
  assertJSON.equalFile(someOutput, `${__dirname}/testcase/my-test/result.json`);
});

Limitation

This library assumes that the JSON is formatted using 2 space indent i.e.

JSON.stringify(JSON.parse(JSON_CONTENT), null, 2) === JSON_CONTENT

In the future, we may try to parse the JSON into an AST to eliminate this limitation. (Currently, we only parse it into an object.)

API

This module exports following members:

  • equal
  • equalFile

equal

assertJSON.equal(actual: Any, expectedJSON: String[, message: String]);

When actual doesn't match expectedJSON, an assertion error is raised.

equalFile

assertJSON.equalFile(actual: Any, expectedJSONFile: String[, message: String]);

Like equal but the JSON is read from a file. The filename will be included in the error report.

Changelog

  • 0.1.5 (May 27, 2019)

    • Fix: null object property throws.
  • 0.1.4 (May 26, 2019)

    • Add: better JSON parse error.
  • 0.1.3 (May 26, 2019)

    • Fix: broken when the diff is near the top/end.
  • 0.1.2 (May 26, 2019)

    • Fix: handle undefined actual.
  • 0.1.1 (May 26, 2019)

    • Fix: remove unused files in the package.
  • 0.1.0 (May 26, 2019)

    • First release.
0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago