Skip to content

Commit c75035c

Browse files
committed
saveJSON test update
1 parent c63b9ca commit c75035c

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1111

1212
### Fixed
1313

14-
* Containers can now be safely nested.
14+
* Containers can now be safely nested. (Container Boundaries)
1515

1616
## [2.2.1]
1717

packages/postcss-container-query/src/containerQuery.js

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ function extractContainerUnits(node, isContainer = false) {
3636
}
3737

3838
/**
39-
* @todo refactor this to use a builder, which'll make testing easier too
4039
* @param {{
4140
* getJSON: function,
4241
* singleContainer: boolean,

packages/postcss-container-query/src/saveJSON.spec.js

+23
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,26 @@ test("should not write contents when file already with same contents", () => {
4141
expect(fs.writeFile).toHaveBeenCalledTimes(0);
4242
});
4343
});
44+
45+
test("should log error in case there's an issue writing the file", () => {
46+
const fs = require("fs");
47+
const cssFilePath = __dirname + "/tmp/saveJSON.test.css";
48+
const jsonFilePath = `${cssFilePath}.json`;
49+
const json = { some: "JSON" };
50+
51+
fs.readFile = jest.fn((filepath, type, cb) => cb(new Error("error")));
52+
fs.writeFile = jest.fn((filepath, content, cb) => cb(new Error("error")));
53+
console.error = jest.fn();
54+
55+
expect.hasAssertions();
56+
57+
return Promise.resolve()
58+
.then(() => saveJSON(cssFilePath, json))
59+
.then(() => {
60+
expect(fs.readFile).toHaveBeenCalledTimes(1);
61+
expect(fs.writeFile).toHaveBeenCalledTimes(1);
62+
expect(fs.writeFile.mock.calls[0][0]).toBe(jsonFilePath);
63+
expect(fs.writeFile.mock.calls[0][1]).toBe(JSON.stringify(json));
64+
expect(console.error).toHaveBeenCalled();
65+
});
66+
});

0 commit comments

Comments
 (0)