Skip to content

Commit 917a6b4

Browse files
committed
react native test
1 parent b8bf3ca commit 917a6b4

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"scripts": {
2323
"test:node": "mocha test/test-*.spec.cjs",
2424
"test:browser": "playwright-test test/test-*.cjs",
25-
"test:es": "mocha test/test-*.spec.js",
25+
"test:react-native": "jest test/test-lib.react-native.spec.js",
26+
"test:es": "mocha test/test-lib.spec.js",
2627
"test:cjs": "npm run test:node && npm run test:browser",
2728
"test:types:ts": "npm test --prefix test/ts-use",
2829
"test:types:esm": "npm test --prefix test/esm-use",
@@ -34,10 +35,18 @@
3435
"author": "Irakli Gozalishvili <[email protected]>",
3536
"homepage": "https://github.com/gozala/web-encoding",
3637
"devDependencies": {
38+
"browser-resolve": "^2.0.0",
39+
"jest": "^26.6.3",
40+
"metro-react-native-babel-preset": "^0.64.0",
3741
"mocha": "8.2.1",
38-
"playwright-test": "1.2.0"
42+
"playwright-test": "1.2.0",
43+
"react-native": "^0.63.4"
3944
},
4045
"optionalDependencies": {
4146
"@sinonjs/text-encoding": "0.7.1"
47+
},
48+
"jest": {
49+
"preset": "react-native",
50+
"transform": {"\\.js$": ["babel-jest", {"presets": ["module:metro-react-native-babel-preset"]}]}
4251
}
4352
}

test/test-lib.react-native.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { TextEncoder, TextDecoder } from "../src/lib.react-native.js"
2+
import assert from "assert"
3+
4+
describe("text encode/decode", () => {
5+
const data = Uint8Array.from([
6+
104,
7+
101,
8+
108,
9+
108,
10+
111,
11+
32,
12+
119,
13+
111,
14+
114,
15+
108,
16+
100,
17+
])
18+
19+
it("can encode text", () => {
20+
const bytes = new TextEncoder().encode("hello world")
21+
assert.deepStrictEqual(bytes, data)
22+
})
23+
24+
it("can decode text", () => {
25+
const text = new TextDecoder().decode(data)
26+
assert.equal(text, "hello world")
27+
})
28+
})

0 commit comments

Comments
 (0)