I wrote some tests, which pass locally, but fail in the pipeline.
Here’s the test:
async displaysMachineTypeWhenOtherMachineIsSelected () {
const { asFragment } = render(
FunctionsFactory.componentFactory({ fetchedState: { machine: mockedMachineState } }),
);
// Functions is an object. It's used in other tests and they all pass
await Functions.selectMachineState1();
Functions.clickEditText();
await Functions.clickOnSelect(DetailsNames.Category);
screen.getByText('Other machine').click();
await waitFor(() => {
expect(screen.getByText(DetailsLabels.MachineType)).toBeInTheDocument();
});
expect(Array.from(document.querySelectorAll('input')).length).toEqual(10);
expect(asFragment()).toMatchSnapshot();
}
it(
'should display machine type dropdown when other machine is selected',
displaysMachineTypeWhenOtherMachineIsSelected,
);
And as I said, it passes locally, but fails in the gitlab pipeline.
Error from gitlab:
● States › Testing machine view › Testing behavior › should display machine type dropdown when other machine is selected
thrown: "Exceeded timeout of 5000 ms for a test.
Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."
64 | machineBehavior(sharedArgs);
65 |
> 66 | it(
| ^
67 | 'should display machine type dropdown when other machine is selected',
68 | displaysMachineTypeWhenOtherMachineIsSelected,
69 | );
at components/pages/states/tests/States.test.tsx:66:7
at components/pages/states/tests/States.test.tsx:62:5
at components/pages/states/tests/States.test.tsx:49:3
at Object.<anonymous> (components/pages/states/tests/States.test.tsx:25:1)
● States › Testing machine view › Testing behavior › should return to machine view on Cancel click
expect(received).toMatchSnapshot()
Snapshot name: `States Testing machine view Testing behavior should return to machine view on Cancel click 1`
- Snapshot - 1
+ Received + 0
@@ -782,11 +782,10 @@
Layers
</div>
</div>
<div
class="ant-tabs-ink-bar ant-tabs-ink-bar-animated"
- style="left: 0px; width: 0px;"
/>
</div>
</div>
<div
class="ant-tabs-nav-operations ant-tabs-nav-operations-hidden"
85 |
86 | Functions.checkIfLabelsArePresent(machineLabels);
> 87 | expect(asFragment()).toMatchSnapshot();
| ^
88 | },
89 | };
90 | };
at Object.returnsToMachineViewOnCancelClick (components/pages/states/tests/testFunctions/machine-view/machineView.ts:87:28)
› 1 snapshot failed.
dependencies from package.json
:
"jest": "^27.0.5",
"babel-jest": "^27.0.5",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^12.0.0",
"jest-cli": "^27.0.5",
Any idea what I’m doing wrong here?