1

グーグルマップをロードするページのテストを書くのに苦労しています。いつもエラーが発生します

"未定義のプロパティ'offsetWidth'を読み取ることができません"

これは、マップスクリプトがマップを保持するために使用するdivをロードするときに、おそらくすでに削除されていることを意味します(divのstyleプロパティのwidthとheightを、幅と高さが100%確実になるように設定しています) 。

私はrequirejsを含む非常に複雑な方法でgmapsスクリプトをロードしていますが、問題がそれに関連しているとは思いません(specRunnerの実行時にrequirejsからエラーが発生した場合でも、すべてが正常に動作します)。

これをどのようにテストする必要がありますか?

4

1 に答える 1

0

使っwaitFor()てみたらうまくいきました。

describe( "Test suite for the 'Event location' Box", function() {
    it( "Should show the map when the appropriate checkbok is clicked and should hide it when clicked again", function() {
        // Wait for the loading of the gmaps. This is simply when the <div> we use as a container has some html
        waitsFor(function() {
            return $('#ai1ec_map_canvas').html() !== '';
        }, "gmaps never loaded", 15000 );
        runs( function() {
            $( "#ai1ec_google_map" ).click();
            expect( $( '#ai1ec_map_canvas' ) ).toBeVisible();
            $( "#ai1ec_google_map" ).click();
            expect( $( '#ai1ec_map_canvas' ) ).not.toBeVisible();
        } );
    } );
} );
于 2012-06-19T15:22:33.447 に答える