Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart - mocking the Element class

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?

like image 847
richard Avatar asked Feb 19 '26 12:02

richard


1 Answers

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.

like image 138
Greg Lowe Avatar answered Feb 22 '26 00:02

Greg Lowe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!