babylon.promises.tests.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * Describes the test suite.
  3. */
  4. describe('Babylon.Promise', () => {
  5. var subject : BABYLON.Engine;
  6. /**
  7. * Loads the dependencies.
  8. */
  9. before(function (done) {
  10. this.timeout(180000);
  11. (BABYLONDEVTOOLS).Loader
  12. .useDist()
  13. .load(function () {
  14. BABYLON.PromisePolyfill.Apply(true);
  15. done();
  16. });
  17. });
  18. /**
  19. * Create a nu engine subject before each test.
  20. */
  21. beforeEach(function () {
  22. subject = new BABYLON.NullEngine({
  23. renderHeight: 256,
  24. renderWidth: 256,
  25. textureSize: 256,
  26. deterministicLockstep: false,
  27. lockstepMaxSteps: 1
  28. });
  29. });
  30. /**
  31. * This test is more an integration test than a regular unit test but highlights how to rely
  32. * on the BABYLON.NullEngine in order to create complex test cases.
  33. */
  34. describe('#Composition', () => {
  35. it('should chain promises correctly', (done) => {
  36. mocha.timeout(10000);
  37. var tempString = "";
  38. var p1 = new Promise((resolve, reject) => {
  39. tempString = "Initial";
  40. resolve();
  41. })
  42. .then(() => {
  43. tempString += " message";
  44. })
  45. .then(() => {
  46. throw new Error('Something failed');
  47. })
  48. .catch(() => {
  49. tempString += " to check promises";
  50. })
  51. .then(() => {
  52. expect(tempString).to.eq("Initial message to check promises");
  53. done();
  54. });
  55. });
  56. });
  57. });