No Description

app-test.js 654B

123456789101112131415161718192021222324252627282930313233343536373839
  1. export default class RNAppTest {
  2. constructor() {
  3. this.tests = []
  4. this.context = null
  5. }
  6. describe (desc, fn) {
  7. this.tests.push({
  8. status : 'running',
  9. result : null,
  10. asserts : [],
  11. desc, fn,
  12. })
  13. }
  14. run (context) {
  15. this.context = context
  16. let promise = Promise.resolve()
  17. for(let i in this.tests) {
  18. promise = promise.then(function(update, data) {
  19. return this.fn(update, data)
  20. }.bind(
  21. this.tests[i],
  22. this.update.bind(this, i)
  23. ))
  24. }
  25. return promise
  26. }
  27. update(i, data) {
  28. Object.assign(this.tests[i], data)
  29. this.context.forceUpdate()
  30. }
  31. }