mirror of
https://github.com/strapi/strapi.git
synced 2025-12-04 11:02:12 +00:00
enhancement: prevent committing tests with only (#21141)
--------- Co-authored-by: Alexandre BODIN <alexandrebodin@users.noreply.github.com>
This commit is contained in:
parent
e0397985ec
commit
d773bfffcd
@ -1,4 +1,11 @@
|
||||
#!/usr/bin/env sh
|
||||
. "$(dirname -- "$0")/_/husky.sh"
|
||||
|
||||
# Check for .only in the staged changes of test files
|
||||
if git --no-pager diff --cached | grep -E '^\+\s*(test|it|describe)\.only'; then
|
||||
echo "Error: .only found in staged changes. Please remove it before committing."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Run lint-staged if no .only is found
|
||||
yarn lint-staged
|
||||
|
||||
@ -20,31 +20,12 @@ const LoginPage = () => {
|
||||
};
|
||||
|
||||
describe('PrivateRoute', () => {
|
||||
// TODO: fix this, it doesn't actually clear the login between tests
|
||||
beforeEach(() => {
|
||||
window.localStorage.clear();
|
||||
});
|
||||
|
||||
it('Authenticated users should be able to access protected routes', async () => {
|
||||
// Login
|
||||
window.localStorage.setItem('jwtToken', JSON.stringify('access-token'));
|
||||
|
||||
render(
|
||||
<>
|
||||
<Route path="/auth/login" component={LoginPage} />
|
||||
<PrivateRoute path="/">
|
||||
<ProtectedPage />
|
||||
</PrivateRoute>
|
||||
</>,
|
||||
{
|
||||
initialEntries: ['/protected'],
|
||||
}
|
||||
);
|
||||
|
||||
// Should see the protected route
|
||||
expect(await screen.findByText('You are authenticated'));
|
||||
});
|
||||
|
||||
it.only('Unauthenticated users should not be able to access protected routes and get redirected', async () => {
|
||||
it('Unauthenticated users should not be able to access protected routes and get redirected', async () => {
|
||||
let testLocation: Location = null!;
|
||||
let testHistory: History = null!;
|
||||
|
||||
@ -85,4 +66,24 @@ describe('PrivateRoute', () => {
|
||||
|
||||
expect(screen.getByText('Please login')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('Authenticated users should be able to access protected routes', async () => {
|
||||
// Login
|
||||
window.localStorage.setItem('jwtToken', JSON.stringify('access-token'));
|
||||
|
||||
render(
|
||||
<>
|
||||
<Route path="/auth/login" component={LoginPage} />
|
||||
<PrivateRoute path="/">
|
||||
<ProtectedPage />
|
||||
</PrivateRoute>
|
||||
</>,
|
||||
{
|
||||
initialEntries: ['/protected'],
|
||||
}
|
||||
);
|
||||
|
||||
// Should see the protected route
|
||||
expect(await screen.findByText('You are authenticated'));
|
||||
});
|
||||
});
|
||||
|
||||
@ -20,7 +20,7 @@ const render = (props) => ({
|
||||
|
||||
describe('AssetCardBase', () => {
|
||||
describe('Interaction', () => {
|
||||
it.only('should call onSelect when the checkbox is clicked', async () => {
|
||||
it('should call onSelect when the checkbox is clicked', async () => {
|
||||
const onSelect = jest.fn();
|
||||
const { getByRole, user } = render({
|
||||
onSelect,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user