Skip to content

Commit

Permalink
test added
Browse files Browse the repository at this point in the history
  • Loading branch information
kev-rs committed Mar 2, 2023
1 parent 6a095ef commit 0404fba
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 19 deletions.
28 changes: 28 additions & 0 deletions __test__/rcl.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { createApi } from '../src/index'
import { describe, expect, beforeAll, afterAll, test } from 'vitest';


const API_URL = 'https://pokeapi.co/api/v2';
const POKE_API_METHODS = ['pokemon', 'type', 'ability'] as const;

type ValidMethods = typeof POKE_API_METHODS[number];

interface Valid {
pokemon: string;
type: string;
ability: string;
};

describe('createApi', () => {
test('should return a proxy object', async () => {


const pokeApi = createApi<Valid>(API_URL, POKE_API_METHODS);
// expect(pokeApi).toBeInstanceOf(new Proxy({}, {}));

const res = await pokeApi.pokemon('1');
console.log({res});

expect(res).toEqual({ name: 'bulbasaur' })
});
})
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0.0",
"version": "1.0.0-rc",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand All @@ -12,8 +12,9 @@
},
"scripts": {
"start": "tsdx watch",
"dev": "tsx watch src/test.ts",
"build": "tsdx build",
"test": "tsdx test",
"test": "vitest",
"lint": "tsdx lint",
"prepare": "tsdx build",
"size": "size-limit",
Expand Down Expand Up @@ -51,7 +52,11 @@
"size-limit": "^8.2.4",
"tsdx": "^0.14.1",
"tslib": "^2.5.0",
"typescript": "^4.9.5"
"tsx": "^3.12.3",
"typescript": "^4.9.5",
"vitest": "^0.29.2"
},
"dependencies": {}
"dependencies": {
"kev-rcl-tsx": "^1.0.0"
}
}
8 changes: 0 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,4 @@ const createApi = <T>(api_url: string, validProps: readonly ValidMethods[]) => {
});
};

// const pokeApi = createApi<Valid>(API_URL, POKE_API_METHODS);
// const res = await pokeApi.pokemon('asd', { limit: 3, offset: 2 })
// const res = await pokeApi.pokemon({ limit: 2, offset: 2 })


// console.log(res);
// console.log(res);

export { createApi, sum };
7 changes: 0 additions & 7 deletions test/blah.test.ts

This file was deleted.

1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
// see https://www.typescriptlang.org/tsconfig to better understand tsconfigs
"include": ["./src/**/*", "types"],
"exclude": ["./__tests__"],
"compilerOptions": {
"module": "esnext",
"lib": ["dom", "esnext"],
Expand Down
10 changes: 10 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
define: {
"import.meta.vitest": "undefined"
},
test: {
include: ["./__test__/**/*.test.{js,ts}"],
}
});

0 comments on commit 0404fba

Please sign in to comment.