Skip to content

Commit c60c592

Browse files
committed
Reduce the scope of expects in strict-mode tests
1 parent adeb53b commit c60c592

File tree

1 file changed

+37
-27
lines changed

1 file changed

+37
-27
lines changed

__tests__/strict-mode.js

+37-27
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ describe("Strict Mode", () => {
1313

1414
describe("by default", () => {
1515
it("should not throw an error when accessing a non-draftable class instance", () => {
16-
expect(() =>
17-
produce({instance: new Foo()}, draft => {
16+
expect.hasAssertions()
17+
18+
produce({instance: new Foo()}, draft => {
19+
expect(() => {
1820
draft.instance.value = 5
19-
})
20-
).not.toThrow()
21+
}).not.toThrow()
22+
})
2123
})
2224
})
2325

@@ -31,21 +33,25 @@ describe("Strict Mode", () => {
3133
})
3234

3335
it("should allow accessing a non-draftable class instance", () => {
34-
expect(() =>
35-
produce({instance: new Foo()}, draft => {
36+
expect.hasAssertions()
37+
38+
produce({instance: new Foo()}, draft => {
39+
expect(() => {
3640
draft.instance.value = 5
37-
})
38-
).not.toThrow()
41+
}).not.toThrow()
42+
})
3943
})
4044

4145
it("should not throw errors when using the `unsafe` function", () => {
42-
expect(() =>
43-
produce({instance: new Foo()}, draft => {
44-
unsafe(() => {
46+
expect.hasAssertions()
47+
48+
produce({instance: new Foo()}, draft => {
49+
unsafe(() => {
50+
expect(() => {
4551
draft.instance.value = 5
46-
})
52+
}).not.toThrow()
4753
})
48-
).not.toThrow()
54+
})
4955
})
5056
})
5157

@@ -55,21 +61,23 @@ describe("Strict Mode", () => {
5561
})
5662

5763
it("should throw an error when accessing a non-draftable class instance", () => {
58-
expect(() =>
59-
produce({instance: new Foo()}, draft => {
60-
draft.instance
61-
})
62-
).toThrow()
64+
expect.hasAssertions()
65+
66+
produce({instance: new Foo()}, draft => {
67+
expect(() => draft.instance).toThrow()
68+
})
6369
})
6470

6571
it("should allow accessing a non-draftable using the `unsafe` function", () => {
66-
expect(() =>
67-
produce({instance: new Foo()}, draft => {
68-
unsafe(() => {
72+
expect.hasAssertions()
73+
74+
produce({instance: new Foo()}, draft => {
75+
unsafe(() => {
76+
expect(() => {
6977
draft.instance.value = 5
70-
})
78+
}).not.toThrow()
7179
})
72-
).not.toThrow()
80+
})
7381
})
7482

7583
it("should require using unsafe for non-draftables in a different scope", () => {
@@ -98,11 +106,13 @@ describe("Strict Mode", () => {
98106
})
99107

100108
it("should allow accessing the class instance", () => {
101-
expect(() =>
102-
produce({instance: new Foo()}, draft => {
109+
expect.hasAssertions()
110+
111+
produce({instance: new Foo()}, draft => {
112+
expect(() => {
103113
draft.instance.value = 5
104-
})
105-
).not.toThrow()
114+
}).not.toThrow()
115+
})
106116
})
107117
})
108118

0 commit comments

Comments
 (0)