在我的应用程序中,用户使用HTML5拖放来处理二进制文件。 这部分代码运行正常。 在chrome中,我拖动一个二进制文件并使用FileReader创建一个arrayBuffer。 这一切似乎都很好。 我正在为这个功能编写测试,我很茫然。 如何将二进制文件加载到单元测试中? 对于我正在测试的代码,我只需要一个arrayBuffer。 目前,我手动创建了arrayBuffer,但这不是一个可持续的解决方案。 为了使我的测试有效,我需要能够随时抛出一个新的二进制文件并进行新的测试。 我的测试环境是testacular + jasmine。
( function() {"use strict"; function loadSimpleDataView() { //instead of defining ArrayBuffer, //I want it to be generated based upon an external file var buffer = new ArrayBuffer(4), dataView = new DataView(buffer), int8View = new Int8Array(buffer); int8View.set([0x00,0x01,0x02,0x03]); return dataView; } describe('mymodule', function() { it('mytest', function() { var dataView = loadSimpleDataView(); expect(dataView).toBeDefined(); //do rest of tests }); }); }());In my application, the user uses HTML5 drag and drop to process a binary file. That part of the code works fine. In chrome, I drag a binary file and use a FileReader to create an arrayBuffer. That all seems to work fine. I am writing tests for this functionality and I am at a loss. How do I load a binary file into my unit test? For the bit of code I am testing, I only need an arrayBuffer. Currently, I am creating the arrayBuffer manually, but that isn't a sustainable solution. In order for my tests to be effective, I need to be able to throw a new binary file in at anytime and make a new test. My testing environment is testacular+jasmine.
( function() {"use strict"; function loadSimpleDataView() { //instead of defining ArrayBuffer, //I want it to be generated based upon an external file var buffer = new ArrayBuffer(4), dataView = new DataView(buffer), int8View = new Int8Array(buffer); int8View.set([0x00,0x01,0x02,0x03]); return dataView; } describe('mymodule', function() { it('mytest', function() { var dataView = loadSimpleDataView(); expect(dataView).toBeDefined(); //do rest of tests }); }); }());更多推荐
发布评论