Skip to content

Commit

Permalink
Add tests for new computed values methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jorge-ramirez-arredondo committed Dec 16, 2024
1 parent 4cefe9c commit acfee3e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/controllers/computed-values/computed-values.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ describe('ComputedValue', () => {
host.update();
expect(computeCount).to.equal(1);
});

it('tryUpdate() updates the controller value', () => {
host.update();
expect(computeCount).to.equal(1);
expect(controller.value).to.equal(`${properties.firstName} ${properties.lastName}`);

properties = {
firstName: 'Jill',
lastName: 'Valentine'
};
expect(controller.tryUpdate()).to.be.true;
expect(controller.value).to.equal(`${properties.firstName} ${properties.lastName}`);
expect(computeCount).to.equal(2);
});
});

describe('Empty Dependencies Array', () => {
Expand Down Expand Up @@ -358,6 +372,30 @@ describe('ComputedValue', () => {
expect(controller.error).to.be.null;
expect(controller.asyncStatus).to.equal(ASYNC_STATUSES.SUCCESS);
});

it('asyncRender() returns different values depending on async status', async() => {
const renderStates = {
success: (value) => `Success: ${value}`,
error: (error) => `Error: ${error}`,
pending: () => 'Pending'
};

// Pending
host.update();
expect(controller.asyncRender(renderStates)).to.equal('Pending');

// Success
resolveCall();
await controller.computeComplete;
expect(controller.asyncRender(renderStates)).to.equal(`Success: ${users[1]}`);

// Error
properties.userId = 2;
host.update();
rejectCall('error message');
await controller.computeComplete;
expect(controller.asyncRender(renderStates)).to.equal('Error: error message');
});
});

describe('Async compute with custom shouldRequestUpdate', () => {
Expand Down

0 comments on commit acfee3e

Please sign in to comment.