Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Mar 16, 2023
1 parent 50ad1ba commit dccab58
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test-app/tests/utils/remote-data/js-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ module('Utils | remote-data | js', function (hooks) {
ctx.json({ errors: [{ status: '404', detail: 'Blog not found' }] })
);
}),
rest.get('/text-error/:id', (req, res, ctx) => {
return res(ctx.status(500), ctx.text('hello world'));
}),
rest.get('/text-success/:id', (req, res, ctx) => {
return res(ctx.text('hello world'));
}),
]);

module('RemoteData', function () {
Expand Down Expand Up @@ -164,6 +170,42 @@ module('Utils | remote-data | js', function (hooks) {
assert.true(test.request.isResolved);
assert.strictEqual(test.request.status, 404);
});

module('works with non-json requests', function () {
test('text with a successful response', async function (assert) {
class Test {
@use request = RemoteData('/text-success/100');
}

let test = new Test();

setOwner(test, this.owner);

assert.strictEqual(test.request.status, null);
await settled();

assert.strictEqual(test.request.value, 'hello world');

assert.strictEqual(test.request.status, 200);
});

test('text with an error response', async function (assert) {
class Test {
@use request = RemoteData('/text-error/100');
}

let test = new Test();

setOwner(test, this.owner);

assert.strictEqual(test.request.status, null);
await settled();

assert.strictEqual(test.request.value, 'hello world');

assert.strictEqual(test.request.status, 200);
});
});
});

module('remoteData', function () {
Expand Down

0 comments on commit dccab58

Please sign in to comment.