Skip to content

Commit ef356ff

Browse files
authored
Fixed unit test (#53)
* fix: Fixed datetime unit-test timezone * fix: Fixed unit-test
1 parent 99a1c56 commit ef356ff

File tree

4 files changed

+29
-953
lines changed

4 files changed

+29
-953
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
"start": "semantic-ui-css-patch && craco start",
7272
"build": "semantic-ui-css-patch && craco build",
7373
"test": "craco test",
74-
"test:cov": "craco test --coverage --no-cache --watchAll",
74+
"test:cov": "craco test --coverage --no-cache --watchAll=false",
75+
"test:u": "craco test -u",
7576
"eject": "craco eject",
7677
"analyze": "source-map-explorer 'build/static/js/*.js'"
7778
},

src/components/Rule/RuleContent.test.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import RuleContent from '.';
77
import { IntlWrapper } from 'components/utils/wrapper';
88
import { hooksFormContainer, ruleContainer, segmentContainer, variationContainer } from 'pages/targeting/provider';
99
import sleep from 'utils/sleep';
10+
import { act } from 'react-test-renderer';
1011

1112
const RuleData = {
1213
id: 'testId1',
@@ -127,26 +128,25 @@ test('RuleContent opt', (done) => {
127128
}
128129
);
129130

130-
await userEvent.click(screen.getByText('Add'));
131-
await sleep(500);
132-
expect(baseElement).toMatchSnapshot();
133-
await userEvent.click(screen.getByText('number'));
134-
await userEvent.click(screen.getByText('datetime'));
135-
await userEvent.click(screen.getByText('semver'));
136-
await userEvent.click(screen.getByText('segment'));
137-
138-
const serve = screen.getAllByText('Please select').pop();
139-
serve && (await userEvent.click(serve));
140-
userEvent.click(screen.getByText('a percentage rollout'));
141-
131+
await act(async () => {
132+
await userEvent.click(screen.getByText('Add'));
133+
expect(baseElement).toMatchSnapshot();
134+
await userEvent.click(screen.getByText('number'));
135+
await userEvent.click(screen.getByText('semver'));
136+
await userEvent.click(screen.getByText('segment'));
137+
138+
const serve = screen.getAllByText('Please select').pop();
139+
serve && (await userEvent.click(serve));
140+
userEvent.click(screen.getByText('a percentage rollout'));
141+
});
142+
142143
const ele = document.createElement('div');
143144
ele.innerHTML = baseElement.innerHTML
144145
.replaceAll(/(\d\d\/\d\d\/\d\d\d\d )*\d\d:\d\d:\d\d/g, 'test_value')
145146
.replaceAll(/\sname="rule_testId1_[\w-]+\w" /g, (_, i) => {
146147
return ` name="test-name-${i}"`;
147148
})
148149
.replaceAll(' rdtActive rdtToday', '');
149-
150150
expect(ele).toMatchSnapshot();
151151

152152
done();

0 commit comments

Comments
 (0)