   [tokenizedBuffer, buffer, changeHandler] = []
 
   beforeEach ->
-    atom.packages.activatePackage('language-javascript', sync: true)
     # enable async tokenization
     TokenizedBuffer.prototype.chunkSize = 5
     jasmine.unspy(TokenizedBuffer.prototype, 'tokenizeInBackground')
+
+    waitsForPromise ->
+      atom.packages.activatePackage('language-javascript')
 
   startTokenizing = (tokenizedBuffer) ->
     tokenizedBuffer.setVisible(true)


  describe "when the buffer contains surrogate pairs", ->
    beforeEach ->
      atom.packages.activatePackage('language-javascript', sync: true)
      buffer = atom.project.bufferForPathSync 'sample-with-pairs.js'
      buffer.setText """
        'abc\uD835\uDF97def'
        //\uD835\uDF97xyz
      """
      tokenizedBuffer = new TokenizedBuffer({buffer})
      fullyTokenize(tokenizedBuffer)

    afterEach ->
      tokenizedBuffer.destroy()


  describe "when the grammar is updated because a grammar it includes is activated", ->
    it "retokenizes the buffer", ->

      waitsForPromise ->
        atom.packages.activatePackage('language-ruby-on-rails')

      waitsForPromise ->
        atom.packages.activatePackage('language-ruby')

      runs ->
        buffer = atom.project.bufferForPathSync()
        buffer.setText "<div class='name'><%= User.find(2).full_name %></div>"
        tokenizedBuffer = new TokenizedBuffer({buffer})
        tokenizedBuffer.setGrammar(atom.syntax.selectGrammar('test.erb'))
        fullyTokenize(tokenizedBuffer)

        {tokens} = tokenizedBuffer.lineForScreenRow(0)
        expect(tokens[0]).toEqual value: "<div class='name'>", scopes: ["text.html.ruby"]

      waitsForPromise ->
        atom.packages.activatePackage('language-html')

      runs ->
        fullyTokenize(tokenizedBuffer)
        {tokens} = tokenizedBuffer.lineForScreenRow(0)
        expect(tokens[0]).toEqual value: '<', scopes: ["text.html.ruby","meta.tag.block.any.html","punctuation.definition.tag.begin.html"]

  describe ".tokenForPosition(position)", ->
    afterEach ->
