Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- run: npm run test

release:
if: "!startsWith(github.event.head_commit.message, '[skip ci]')"
if: ${{ !startsWith(github.event.head_commit.message, '[skip ci]') }}
needs: install-and-test
runs-on: ubuntu-latest
name: "Create a new release & update changelog using semantic-release"
Expand All @@ -40,7 +40,7 @@ jobs:

publish-to-github-registry:
needs: release
if: "contains(${{ needs.release.outputs.new-release-published }}, 'true')"
if: ${{ contains(needs.release.outputs.new-release-published, 'true') }}
runs-on: ubuntu-latest
name: "Releases package to Github Packages registry"
steps:
Expand All @@ -61,7 +61,7 @@ jobs:

publish-to-npm:
needs: release
if: "contains(${{ needs.release.outputs.new-release-published }}, 'true')"
if: ${{ contains(needs.release.outputs.new-release-published, 'true') }}
runs-on: ubuntu-latest
name: "Releases package to NPM registry"
steps:
Expand All @@ -78,4 +78,4 @@ jobs:
- run: npm version ${{ needs.release.outputs.new-release-version }} --no-git-tag-version --no-commit-hooks --allow-same-version
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.NPMJS_READWRITE_TOKEN}}
NODE_AUTH_TOKEN: ${{ secrets.NPMJS_READWRITE_TOKEN }}
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
module.exports = {
preset: "ts-jest",
testEnvironment: "node",
rootDir: "tests",
roots: ["<rootDir>/src"],
testMatch: ["**/*.test.ts"],
};
54 changes: 54 additions & 0 deletions src/helpers/hasQueryParams.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { hasQueryParam } from "./hasQueryParams";

describe("hasQueryParam", () => {
it("should return true when the object contains the specified key", () => {
const query = { id: 123, name: "test" };
expect(hasQueryParam(query, "id")).toBe(true);
});

it("should return true even if the value of the key is null", () => {
// The key exists, even if the value is null
const query = { filter: null };
expect(hasQueryParam(query, "filter")).toBe(true);
});

it("should return true even if the value of the key is undefined", () => {
// The key exists explicitly, even if undefined
const query = { sort: undefined };
expect(hasQueryParam(query, "sort")).toBe(true);
});

it("should return false if the query is null", () => {
// typeof null is 'object', so this checks the query !== null logic
expect(hasQueryParam(null, "id")).toBe(false);
});

it("should return false if the query is undefined", () => {
expect(hasQueryParam(undefined, "id")).toBe(false);
});

it("should return false if the query is an array", () => {
// Arrays are objects in JS, so this checks the !Array.isArray logic
const query = ["id", "value"];
expect(hasQueryParam(query, "0")).toBe(false);
expect(hasQueryParam(query, "id")).toBe(false);
});

it("should return false if the query is a primitive string", () => {
expect(hasQueryParam("some-string", "length")).toBe(false);
});

it("should return false if the query is a primitive number", () => {
expect(hasQueryParam(12345, "toFixed")).toBe(false);
});

it("should return false if the object does not contain the key", () => {
const query = { name: "test" };
expect(hasQueryParam(query, "age")).toBe(false);
});

it("should be case-sensitive regarding the key", () => {
const query = { ID: 123 };
expect(hasQueryParam(query, "id")).toBe(false);
});
});
5 changes: 0 additions & 5 deletions tests/sample.test.ts

This file was deleted.