aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


tools/client/game_test_test.mjs (673B)


      1 import assert from 'node:assert/strict';
      2 import test from 'node:test';
      3 import {GameTest} from './game_test.mjs';
      4 
      5 test('async condition waits for a resolved true value', async () => {
      6   const game = new GameTest();
      7   let calls = 0;
      8 
      9   const result = await game.waitFor('resolved condition', async () => ++calls === 2);
     10 
     11   assert.equal(result, true);
     12   assert.equal(calls, 2);
     13 });
     14 
     15 test('async condition propagates its failure', async () => {
     16   const game = new GameTest();
     17   const failure = new Error('controller failed');
     18 
     19   const result = game.waitFor('failed controller', async () => { throw failure; });
     20 
     21   await assert.rejects(result, error => error === failure);
     22 });