Skip to content

Commit

Permalink
feat: do more good stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredLunde committed Oct 2, 2021
1 parent ad1d5da commit 983eb6f
Show file tree
Hide file tree
Showing 7 changed files with 245 additions and 74 deletions.
5 changes: 0 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ module.exports = {
collectCoverageFrom: ["<rootDir>/src/**/*.{ts,tsx}"],
setupFilesAfterEnv: ["./test/setup.ts"],
snapshotResolver: "./test/resolve-snapshot.js",
globals: {
"ts-jest": {
babelConfig: true,
},
},
transformIgnorePatterns: [],
// This is the only part which you can keep
// from the above linked tutorial's config:
Expand Down
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@swc-node/core": "^1.6.0",
"@swc-node/jest": "^1.3.2",
"@testing-library/jest-native": "^4.0.2",
"@testing-library/react": "^12.1.1",
"@testing-library/react-native": "^7.2.0",
"@types/jest": "latest",
"@types/react-native": "^0.65.3",
Expand All @@ -37,6 +38,7 @@
"prettier": "latest",
"react": "^17.0.2",
"react-native": "^0.65.1",
"react-test-renderer": "^17.0.2",
"ts-jest": "^27.0.5",
"typescript": "latest"
},
Expand Down Expand Up @@ -95,7 +97,10 @@
"eslintConfig": {
"extends": [
"lunde"
]
],
"rules": {
"testing-library/prefer-screen-queries": "off"
}
},
"eslintIgnore": [
"node_modules",
Expand Down Expand Up @@ -137,8 +142,8 @@
"type-fest": "^2.3.4"
},
"peerDependencies": {
"@types/react-native": ">=0.20",
"react": ">=16",
"react-native": ">=0.20",
"@types/react-native": ">=0.20"
"react-native": ">=0.20"
}
}
57 changes: 55 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 15 additions & 3 deletions src/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@

exports[`styles() should pass 1`] = `
Object {
"color": "red",
"color": "blue",
}
`;

exports[`styles() should too pass 1`] = `
Object {
"color": "red",
"marginBottom": 1,
"marginLeft": 1,
"marginRight": 1,
"marginTop": 1,
}
`;

exports[`styles() should too pass 2 1`] = `
Object {
"color": "red",
"marginBottom": 1,
"marginLeft": 1,
"marginRight": 1,
"marginTop": 1,
}
`;

Expand All @@ -31,6 +37,12 @@ Object {
}
`;

exports[`styles.one() should also pass 1`] = `
Object {
"color": "blue",
}
`;

exports[`styles.one() should pass 1`] = `
Object {
"color": "red",
Expand Down
43 changes: 40 additions & 3 deletions src/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import { render } from "@testing-library/react-native";
import * as React from "react";
import * as RN from "react-native";
import "@testing-library/jest-native/extend-expect";
import { createStyles } from "./index";

describe("styles()", () => {
const { styles } = createStyles({
const { styles, styled } = createStyles({
tokens: {
spacing: [1, 2, 3, 4],
},
} as const,
});

it("should pass", () => {
const style = styles({
default: `
color: red;
`,
foo: {
color: "blue",
},
});

expect(style("default")).toMatchSnapshot();
expect(style("default", "foo")).toMatchSnapshot();
});

it("should too pass", () => {
Expand Down Expand Up @@ -49,6 +56,28 @@ describe("styles()", () => {

expect(style("default", "other")).toMatchSnapshot();
});

it("should also pass", () => {
const StyledView = styled.View(({ spacing }) => ({
margin: spacing[0],
}));

const view = render(
<StyledView style="background-color: blue;" testID="foo" />
);

expect(view.getByTestId("foo")).toHaveStyle({
backgroundColor: "blue",
margin: 1,
});
});

it("should also pass 3", () => {
const StyledView = styled(RN.View, { backgroundColor: "blue" });
const view = render(<StyledView testID="foo" />);

expect(view.getByTestId("foo")).toHaveStyle({ backgroundColor: "blue" });
});
});

describe("styles.one()", () => {
Expand All @@ -64,6 +93,14 @@ describe("styles.one()", () => {
`;
expect(style()).toMatchSnapshot();
});

it("should also pass", () => {
const style = styles.one<RN.TextStyle>(() => ({
color: "blue",
}));

expect(style()).toMatchSnapshot();
});
});

describe("styles.cls()", () => {
Expand Down
Loading

0 comments on commit 983eb6f

Please sign in to comment.