Merge pull request #9978 from asvetliakov/match-media-mock

Type definition for match-media-mock
This commit is contained in:
Zhengbo Li
2016-07-07 00:27:17 -07:00
committed by GitHub
2 changed files with 50 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
/// <reference path="./match-media-mock.d.ts" />
import { create } from "match-media-mock";
const matchMediaMock = create();
matchMediaMock.setConfig({type: 'screen', width: 1200})
matchMediaMock('(max-width: 991px)').matches // false
matchMediaMock('(max-width: 1240px)').matches // true
const mediaQueryList = matchMediaMock('(max-width: 991px)');
const listener = (mql: MediaQueryList) => { };
mediaQueryList.addListener(listener)
mediaQueryList.removeListener(listener)

35
match-media-mock/match-media-mock.d.ts vendored Normal file
View File

@@ -0,0 +1,35 @@
// Type definitions for match-media-mock 0.1.0
// Project: https://github.com/azazdeaz/match-media-mock
// Definitions by: Alexey Svetliakov <https://github.com/asvetliakov>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module "match-media-mock" {
/**
* Mock configuration options
*/
interface ConfigOptions {
/**
* Screen type
*/
type?: string;
/**
* Screen height
*/
height?: number;
/**
* Screen width
*/
width?: number;
}
interface MatchMediaMock {
/**
* Set configuration
*/
setConfig(config: ConfigOptions): void;
/**
* Execute query based on provided configuration
*/
(query: string): MediaQueryList;
}
export function create(): MatchMediaMock;
}