Skip to content

Commit c21fa5d

Browse files
committed
Merge pull request #33 from g4rcez/tests
feat: add tests
2 parents 58eca14 + 0aea278 commit c21fa5d

File tree

6 files changed

+17
-18
lines changed

6 files changed

+17
-18
lines changed

cypress.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { defineConfig } from "cypress";
22

33
export default defineConfig({
4+
video: false,
5+
screenshotsFolder: false,
46
e2e: {
5-
nodeVersion: "system",
67
baseUrl: "http://localhost:5173",
78
},
89
component: {

cypress/e2e/brouther.cy.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
describe("template spec", () => {
1+
describe("Should test Brouther behaviors", () => {
22
before(() => cy.visit("/"));
33

4-
const testLinkSelector = (selector: string, path: string) => {
5-
cy.get(selector).click();
6-
cy.url().should("equal", `http://localhost:5173${path}`);
7-
};
8-
9-
it("passes", () => {
4+
it("Should redirect to correct URL", () => {
105
cy.get("nav>ul>li>a[href='/']");
6+
cy.get("nav>ul>li>a[href='/users?sort=desc']").click().url().should("be.equal", "http://localhost:5173/users?sort=desc");
7+
cy.get("#users>li>a").first().should("contain.text", "Spider Man");
118

12-
const secondLink = "/user/TRY_TO_CHANGE_URL/address/?sort=asc";
13-
testLinkSelector(`nav>ul>li:nth-child(2)>a[href='${secondLink}']`, secondLink);
14-
15-
cy.get("nav>ul>li>a[href='/404']").click();
16-
cy.get("div.error");
9+
cy.visit("/users?sort=asc");
10+
cy.get("#users>li>a").first().should("contain.text", "Batman");
1711
});
1812
});

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
"test:types": "tsc -p ./tsconfig.test.json",
3333
"test:watch": "vitest watch",
3434
"cy": "cypress open",
35-
"cy:run": "cypress run",
35+
"cy:chrome": "cypress run --browser chrome",
36+
"cy:electron": "cypress run --browser electron",
37+
"cy:run": "\npm run cy:chrome && \npm cy:electron",
3638
"cy:browser": "start-server-and-test start http://localhost:5173 cy:run",
3739
"typedoc": "typedoc --out docs src/index.ts"
3840
},

playground/src/pages/users.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default function UsersPage() {
99

1010
return (
1111
<div>
12-
<ul>
12+
<ul id="users">
1313
{sortedList.map((user) => (
1414
<li key={user.id}>
1515
<Link href={router.link(router.links.user, { id: user.id })}>

src/router/link.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ export type LinkProps<Path extends string> = Omit<
2323
? { query: QueryString.Parse<Path> }
2424
: { query?: QueryString.Parse<Path> });
2525

26+
const httpRegex = /^https?:\/\//;
27+
2628
export const Link = <TPath extends string>({ href, state, replace = false, onClick, query, paths, ...props }: LinkProps<TPath>) => {
2729
const { push, replace: _replace } = useNavigation();
2830
const contextHref = useHref();
2931
const basename = useBasename();
30-
const _href = join(basename, mergeUrlEntities(href, paths, query));
32+
const _href = httpRegex.test(href) ? href : join(basename, mergeUrlEntities(href, paths, query));
3133
const _onClick: NonNullable<typeof onClick> = (event) => {
3234
if (props.target === undefined && props.target !== "_self") event.preventDefault();
3335
if (_href === contextHref) return;

0 commit comments

Comments
 (0)