blob: a33ac5ed0975f03e163f92f9fad44396aeb9c16e [file] [log] [blame]
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library mock_test;
import 'package:js/js.dart';
import 'package:expect/minitest.dart';
external void eval(String code);
class JSClass {}
class DerivedA extends JSClass {
external DerivedB get derivedB;
external DerivedA get derivedA;
class DerivedB extends JSClass {}
class MockDerivedA implements DerivedA {
final DerivedB derivedB = new MockDerivedB();
class MockDerivedB implements DerivedB {}
void main() {
function inherits(child, parent) {
if (child.prototype.__proto__) {
child.prototype.__proto__ = parent.prototype;
} else {
function tmp() {};
tmp.prototype = parent.prototype;
child.prototype = new tmp();
child.prototype.constructor = child;
function JSClass() {
function DerivedA() {;
this.derivedB = new DerivedB();
inherits(DerivedA, JSClass);
function DerivedB() {;
inherits(DerivedB, JSClass);
var derivedA = new DerivedA();
test('js', () {
var jsA = derivedA;
// `is` checks will return true for any two JS interop types.
expect(jsA is JSClass, isTrue);
expect(jsA is DerivedA, isTrue);
expect(jsA is DerivedB, isTrue);
expect(jsA is! MockDerivedA, isTrue);
expect(jsA is! MockDerivedB, isTrue);
test('mock', () {
var mockA = new MockDerivedA();
expect(mockA is JSClass, isTrue); //# 44252: ok
expect(mockA is DerivedA, isTrue);
// Fails in dart2js
// expect(mockA is! DerivedB, isTrue);
expect(mockA is MockDerivedA, isTrue);
expect(mockA is! MockDerivedB, isTrue);
var mockB = mockA.derivedB;
expect(mockB is JSClass, isTrue); //# 44252: continued
// Fails in dart2js
// expect(mockB is! DerivedA, isTrue);
expect(mockB is DerivedB, isTrue);
expect(mockB is! MockDerivedA, isTrue);
expect(mockB is MockDerivedB, isTrue);