## 事象
以下のようなコードを書いて実行しても、結果が右側に表示されない。
![[Pasted image 20240117152924.png]]
以下のようにawait部をコメントアウトすれば動作する。
```js
test("name is correct", async () => {
//const data = await fetch("http://localhost:3000/users?user_id=eq.3").then(r => r.json())
//console.log(data)
expect(res.getBody().item.name).to.equal("hoge")
})
```
### 追加調査
[[Bruno]]のランタイムを追ってみる。
> [bruno/packages/bruno\-js/src/runtime/test\-runtime\.js at main · usebruno/bruno](https://github.com/usebruno/bruno/blob/main/packages/bruno-js/src/runtime/test-runtime.js)
`test`関数の正体は以下。
```js
const __brunoTestResults = new TestResults();
const test = Test(__brunoTestResults, chai);
```
`Test`は`test.js`から読み込まれている。
```js
const Test = (__brunoTestResults, chai) => async (description, callback) => {
try {
await callback();
__brunoTestResults.addResult({ description, status: 'pass' });
} catch (error) {
```
これを見る限り **`Test(...)`を呼び出すと[[async function (JavaScript)|async function]]を返却するし、`callback()`もawaitされている**。つまり `test` は [[async function (JavaScript)|async function]]である。
## 原因
`test`関数をawaitしていなかったから。`test`関数全体が[[Promise (JavaScript)|Promise]]を返すようになるが、それを待つ処理が入っていなかった。
## 解決方法
awaitをつける。
```js
await test("name is correct", async () => {
const data = await fetch("http://localhost:3000/users?user_id=eq.3").then(r => r.json())
console.log(data)
expect(res.getBody().item.name).to.equal("hoge")
})
```