{"action":"opened","issue":{"url":"https://api.github.com/repos/angular/zone.js/issues/1120","repository_url":"https://api.github.com/repos/angular/zone.js","labels_url":"https://api.github.com/repos/angular/zone.js/issues/1120/labels{/name}","comments_url":"https://api.github.com/repos/angular/zone.js/issues/1120/comments","events_url":"https://api.github.com/repos/angular/zone.js/issues/1120/events","html_url":"https://github.com/angular/zone.js/issues/1120","id":343094658,"node_id":"MDU6SXNzdWUzNDMwOTQ2NTg=","number":1120,"title":"fakeAsync cannot work with FileReader event","user":{"login":"Teamop","id":8519685,"node_id":"MDQ6VXNlcjg1MTk2ODU=","avatar_url":"https://avatars1.githubusercontent.com/u/8519685?v=4","gravatar_id":"","url":"https://api.github.com/users/Teamop","html_url":"https://github.com/Teamop","followers_url":"https://api.github.com/users/Teamop/followers","following_url":"https://api.github.com/users/Teamop/following{/other_user}","gists_url":"https://api.github.com/users/Teamop/gists{/gist_id}","starred_url":"https://api.github.com/users/Teamop/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Teamop/subscriptions","organizations_url":"https://api.github.com/users/Teamop/orgs","repos_url":"https://api.github.com/users/Teamop/repos","events_url":"https://api.github.com/users/Teamop/events{/privacy}","received_events_url":"https://api.github.com/users/Teamop/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-07-20T12:47:41Z","updated_at":"2018-07-20T12:47:41Z","closed_at":null,"author_association":"NONE","body":"## verison\r\nzone.js: 0.8.26\r\n\r\n## issue\r\nFor testing the `FileReader` event, like `onload`, if with `setTimeout`, test case can pass, while with `fakeAsync`, failed. \r\nThe below is the code that can reproduce this issue and can just be pasted in the current test spec and run\r\n\r\n```javascript\r\n// function need to be tested\r\nfunction fileReaderTest(blob: Blob): number {\r\n  const reader = new FileReader();\r\n\r\n  let num = 0;\r\n\r\n  reader.onload = () => {\r\n    num++;\r\n  };\r\n\r\n  reader.readAsText(blob);\r\n\r\n  return num;\r\n}\r\n\r\n// test the above function\r\nfdescribe('', () => {\r\n  let blob: Blob;\r\n\r\n  beforeEach(() => {\r\n    const data = 'Hello, World!';\r\n    blob = new Blob([data]);\r\n  });\r\n\r\n  // can pass\r\n  it('with setTimeout', () => {\r\n    const number = fileReaderTest(blob);\r\n\r\n    setTimeout(() => {\r\n      expect(number).toEqual(1);\r\n    });\r\n  });\r\n\r\n  // fail\r\n  it('with fakeAsync', () => {\r\n    let FakeAsyncTestZoneSpec = (Zone as any)['FakeAsyncTestZoneSpec'];\r\n    let testZoneSpec: any;\r\n    let fakeAsyncTestZone: Zone;\r\n\r\n    testZoneSpec = new FakeAsyncTestZoneSpec('name');\r\n    fakeAsyncTestZone = Zone.current.fork(testZoneSpec);\r\n\r\n    const num = fileReaderTest(blob);\r\n\r\n    fakeAsyncTestZone.run(() => {\r\n\r\n      testZoneSpec.tick(100);\r\n      testZoneSpec.tick(100);\r\n      testZoneSpec.flush(); \r\n      testZoneSpec.flushMicrotasks();\r\n      expect(num).toEqual(1);\r\n    });\r\n  });\r\n});\r\n\r\n```\r\n\r\n## Background\r\nToday when I tried to write some unit tests for a function with `FileReader`, I got this issue. But I'm not sure if it's really a bug or just my misuse.\r\n\r\nthanks"}}
{"actor":{"display_login":"Teamop"}}