Both beforeEach() functions get called (as opposed to this beforeEach() overriding the function by the same name in the outer scope), so you need to keep beforeEach() and afterEach() balanced for the mock editor code. It might be cleanest to add afterEach() here (and below), and the move the other beforeEach()/afterEach() functions above to the inner scope(s).