What's the T3-approved framework for testing apis?

Im also using trpc-openapi to generate reset endpoints for external users of my app. so it would be nice if I could test those as well.
11 Replies
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Neto
Neto•2y ago
there is no "approved" solution
Neto
Neto•2y ago
Create T3 App
tRPC 🚀 Create T3 App
The best way to start a full-stack, typesafe Next.js app.
Neto
Neto•2y ago
from the docs as a test using vitest
Tom
Tom•2y ago
@chalop im already using tRPC i was looking more for a way to add tests to my code base could have made that clearer @Neto have you used vitest before? do you like it? are there other options i should try?
Neto
Neto•2y ago
for the typescript ecosystem vitest is prob by far the best the jest "sucessor" built on top of vite
Tom
Tom•2y ago
awesome ill give it a shot then tyvm
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Neto
Neto•2y ago
yea vite has its own .env rules
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Tom
Tom•2y ago
@Neto ive gotten myself up and running with vitest. seems pretty good so far, but im having issues with one test
/* games should be reset */
tournament.games
.filter((game) => !gameUtils.isBye(game))
.forEach((game) => {
expect(game).toEqual(
expect.objectContaining({
state: GameState.AVAILABLE,
activeSince: undefined,
availableSince: undefined,
calledSince: undefined,
endTime: undefined,
})
);
});
/* games should be reset */
tournament.games
.filter((game) => !gameUtils.isBye(game))
.forEach((game) => {
expect(game).toEqual(
expect.objectContaining({
state: GameState.AVAILABLE,
activeSince: undefined,
availableSince: undefined,
calledSince: undefined,
endTime: undefined,
})
);
});
this throws this error:
- Expected - 2
+ Received + 33

- ObjectContaining {
+ "Object {
"activeSince": undefined,
"availableSince": undefined,
"calledSince": undefined,
"endTime": undefined,
- "state": 1,
+ "id": "W-8",
+ "locationID": undefined,
+ "name": "W:2-1",
+ "nextGameSlotIDs": Array [
+ "W-12+0",
+ "L-7+0",
+ ],
+ "round": 1,
+ "slots": Array [
+ Object {
+ "checkInTime": undefined,
+ "gameID": "W-8",
+ "isWinner": false,
+ "playerID": "a31fecb17f4c4da9",
+ ...
}
- Expected - 2
+ Received + 33

- ObjectContaining {
+ "Object {
"activeSince": undefined,
"availableSince": undefined,
"calledSince": undefined,
"endTime": undefined,
- "state": 1,
+ "id": "W-8",
+ "locationID": undefined,
+ "name": "W:2-1",
+ "nextGameSlotIDs": Array [
+ "W-12+0",
+ "L-7+0",
+ ],
+ "round": 1,
+ "slots": Array [
+ Object {
+ "checkInTime": undefined,
+ "gameID": "W-8",
+ "isWinner": false,
+ "playerID": "a31fecb17f4c4da9",
+ ...
}
not really sure why its not working nevermind. turns out my test was just actually wrong 😛
Want results from more Discord servers?
Add your server