Closed Bug 1044743 Opened 10 years ago Closed 10 years ago

Use the correct promise testing pattern in keyboard unit tests

Categories

(Firefox OS Graveyard :: Gaia::Keyboard, defect)

x86
macOS
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 1047837

People

(Reporter: timdream, Assigned: watson.serrano, Mentored)

References

Details

(Whiteboard: [good first bug][p=3][mentor-lang=zh])

It turned out I was using the wrong pattern for testing promise outcome in many of the unit tests since I start using promise in keyboard app.

For detail, please read dev-gaia: "aync testing with promises in mocha"

We need to correct these pattern into the correct one so that these tests, when failed, won't timed out but correctly display the error messages.

Marking dependency to bug 1040598 because this bug need to wait for the code changes there.

Blocks bug 1040603 because to write a promise-based queue we need to first properly test the current ones.
I am not entirely sure if this bug is still valid as the pattern might have been corrected on other bugs.

Anyway, the correct pattern should be

PromiseToAssert.then(function(result) {
  ... (asset the result and other properties on this timing)
}, function(e) {
  e && return e;
  assert.isTrue(false, 'Should not reject.');
}).then(done, done);

IMHO this is better than what was suggested on dev-gaia because you don't need to create another function block.
Sorry, this should be 

PromiseToAssert.then(function(result) {
  ... (asset the result and other properties on this timing)
}, function(e) {
  if (e) { return e; }
  assert.isTrue(false, 'Should not reject.');
}).then(done, done);
This seems like a good first bug. 
Can I do it?
Please do. Do you know where to start?
Assignee: nobody → watson.serrano
Status: NEW → ASSIGNED
Flags: needinfo?(watson.serrano)
Hi Tim Thanks a lot for leting me do this bug.

I don't really know where to start. 

I imagine that the first thing to do is to read all that there is related to tests in Gaia probably starting with https://developer.mozilla.org/en-US/Firefox_OS/Platform/Automated_testing/Gaia_unit_tests

I could not find "aync testing with promises in mocha" can you please point me to it so that I don't miss it.

Second I think I will have to go to gaia/apps/keyboard/test and search for all the tests that have the wrong patterns and fix them.

Once the code is correct I will have to try to submit a patch following the instructions on https://developer.mozilla.org/en-US/Firefox_OS/Developing_Gaia/Submitting_a_Gaia_patch

Am I on the right track?
Flags: needinfo?(watson.serrano)
Yes, that's the plan. Thank you for the contribution.
Dup over to bug 1047837 since I've fix this in the patch along the way, and inactivity of this bug.
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.