Skip to content

Commit

Permalink
testing basics with jest
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Hallock committed Aug 13, 2021
1 parent 8e3e007 commit f53aca1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"scripts": {
"dev": "tsc --watch",
"build": "tsc",
"prepublish": "npm run build"
"prepublish": "npm run build",
"test": "jest"
},
"repository": {
"type": "git",
Expand All @@ -26,7 +27,11 @@
},
"homepage": "https://github.com/pd4d10/vite-plugin-svgr#readme",
"devDependencies": {
"@babel/preset-env": "^7.15.0",
"@babel/preset-typescript": "^7.15.0",
"@types/node": "^15.12.2",
"jest": "^27.0.6",
"ts-node": "^10.2.0",
"typescript": "^4.3.2",
"vite": "^2.3.7"
},
Expand Down
44 changes: 44 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {join} from 'path';
import svgr from '.';
describe('svgr plugin', () => {
it('should observe defaultExport', async () => {
expect(
await svgr({defaultExport: true}).transform(
'// some code here',
join(__dirname, 'test.svg')))
.toMatchInlineSnapshot(`
Object {
"code": "import * as React from \\"react\\";
function ReactComponent(props) {
return /* @__PURE__ */ React.createElement(\\"svg\\", {
xmlns: \\"http://www.w3.org/2000/svg\\",
...props
}, /* @__PURE__ */ React.createElement(\\"text\\", null, \\"SVG\\"));
}
export default ReactComponent;
",
"map": null,
}
`)
})
it('should work with no configs', async () => {
expect(
await svgr().transform(
'// some code here',
join(__dirname, 'test.svg')))
.toMatchInlineSnapshot(`
Object {
"code": "import * as React from \\"react\\";
function ReactComponent(props) {
return /* @__PURE__ */ React.createElement(\\"svg\\", {
xmlns: \\"http://www.w3.org/2000/svg\\",
...props
}, /* @__PURE__ */ React.createElement(\\"text\\", null, \\"SVG\\"));
}
export { ReactComponent };
",
"map": null,
}
`)
})
})

0 comments on commit f53aca1

Please sign in to comment.