3

I am trying to create a unit test that requires me to mock the Element class

So my code looks something like

import 'dart:html';

import 'package:unittest/unittest.dart';
import 'package:mock/mock.dart';


@proxy

class MockElement extends Mock implements Element{}

void main(){

  test("",(){
    MockView view = new MockView();  
    MockElement element = new MockElement();

When I run this I get the following message

The built-in library 'dart:html' is not available on the stand-alone VM. 'file:///C:/Users/Schmidt/Documents/GitHub/PicasaWebAlbumDisplay/test/picasaphotopresentor_test.dart': error: line 1 pos 1: library handler failed import 'dart:html'; ^

I need to import html to have the definition of the Element class, so I am stuck at this point.

Any ideas?

Daniel
  • 4,051
  • 2
  • 28
  • 46
richard
  • 2,887
  • 5
  • 26
  • 36

2 Answers2

1

Depending on your requirements, you may be able to use html5lib. However, it is not yet fully compatible with dart:html, but aims to be.

Another option worth exploring is testing with a headless browser. See this example.

Greg Lowe
  • 15,430
  • 2
  • 30
  • 33
0

Instead of proxy, try using abstract factory pattern. The Application uses Element Factory to get instance. It can acquire the instance through some global variable. When the Application is not being tested, this instance would be the Factory Implemenation that creates the real Implementation for the Application query. The Test module can also implement the Factory interface and can set the global variable to hold a reference to itself when it needs to test the application. So you will need Application, Test, Factory Implementation, Implementation, Test, Factory interface, and database interface.

Tuan
  • 11
  • 3