Skip to content

Commit

Permalink
test deepFreeze (#1730)
Browse files Browse the repository at this point in the history
* test deepFreeze

* test deepFreeze

* fmt
  • Loading branch information
imagineLife committed Jun 5, 2022
1 parent 5126e7b commit 2e1387b
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: '🐛 Bug report'
name: "🐛 Bug report"
description: Create a report to help us improve
body:
- type: markdown
Expand Down Expand Up @@ -64,7 +64,7 @@ body:
label: react-grid-layout library version
description: What version of the `react-grid-layout` library are you using?
validations:
required: true
required: true
- type: input
id: os
attributes:
Expand Down Expand Up @@ -102,4 +102,4 @@ body:
For more information on the supported file image/file types and the file size limits, please refer
to the following link: https://docs.github.com/en/github/writing-on-github/working-with-advanced-formatting/attaching-files
placeholder: |
You can drag your video or image files inside of this editor ↓
You can drag your video or image files inside of this editor ↓
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ contact_links:
about: Ask long-form questions and discuss ideas.
- name: 👥 Community Code Examples for `react-grid-layout`
url: https://codesandbox.io/search?refinementList%5Bnpm_dependencies.dependency%5D%5B0%5D=react-grid-layout&refinementList%5Btemplate%5D%5B0%5D=create-react-app&refinementList%5Btemplate%5D%5B1%5D=create-react-app-typescript&page=1&configure%5BhitsPerPage%5D=12
about: See `react-grid-layout` examples created by our community of users
about: See `react-grid-layout` examples created by our community of users
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,4 @@
"yarn fmt"
]
}
}
}
59 changes: 59 additions & 0 deletions test/spec/utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,4 +695,63 @@ describe("deepFreeze", () => {
);
expect(JSON.stringify(deepFreezeResult)).toBe('{"a":"a","b":{"b":"c"}}');
});
it('gets nested key value', () => {
const res = deepFreeze(
{ one: "a", two: { b: "c" } },
{ set: true, get: true }
)

const val = res.two.b
expect(val).toBe('c')
})
it('defaults option prop to get: true', () => {
const res = deepFreeze(
{ one: "a", two: { b: "c" } },
);

expect(res.two.b).toBe('c')
})
it("does not pass check `if(options.set)` ", () => {
const res = deepFreeze({ one: "a" }, {set: false, get:false});
expect(res.one).toBe("a");
});


it('returns `toJSON`', () => {
const res = deepFreeze({ a: 'toJSON' })
expect(res.a.toString()).toBe(`toJSON`)
})
describe('throws "unknown prop" error', () => {
it('when setting bad key', () => {
try {
const res = deepFreeze(
{ one: "a", two: { b: "c" } },
{ set: true, get: false }
);
// $FlowIgnore to test the error throw
res.badProp = "dog";
} catch (e) {
expect(e.message).toBe(
'Can not set unknown prop "badProp" on frozen object.'
);
}
})
it("when getting bad key", () => {
try {
const res = deepFreeze(
{ one: "a", two: { b: "c" } },
{ set: true, get: true }
);
// $FlowIgnore to test the error throws
res.badProp;

} catch (e) {
expect(e.message).toBe(
'Can not get unknown prop "badProp" on frozen object.'
);
}
});
})


});

0 comments on commit 2e1387b

Please sign in to comment.