This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ npm test | |
> [email protected] test /home/user/project | |
> jest | |
PASS src/__tests__/WithErrorExample.test.jsx | |
Example | |
✓ Test (108ms) | |
Test Suites: 1 passed, 1 total |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { mount, ReactWrapper } from 'enzyme'; | |
import { Modal } from 'react-bootstrap'; | |
// The Enzyme selector query will not work because the actual inside HTML of the modal lives else where in the DOM | |
// via portals. See: https://react-bootstrap.github.io/react-overlays/#portals | |
function getWrapperForModalPortal(parentWrapper) { | |
// The Modal instance provides a reference to HTML content: | |
// [1] https://github.com/react-bootstrap/react-bootstrap/blob/dddb9b966c7f3e79495be5c5730f7cce04813aaf/src/Modal.js#L228 | |
// [2] https://github.com/react-bootstrap/react-bootstrap/blob/419051127d913bbb149e81ed221500108ba0d7f3/test/ModalSpec.js#L32 | |
const modalInstance = parentWrapper.find(Modal).getNode()._modal.getDialogElement(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 3. Use the response | |
// ================================ | |
responsePromise | |
// 3.1 Convert the response into JSON-JS object. | |
.then(function(response) { | |
return response.json(); | |
}) | |
// 3.2 Do something with the JSON data | |
.then(function(jsonData) { | |
console.log(jsonData); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.controller('MyCtrl', function($scope, $q) { | |
const promise1 = somethingThatReturnsAPromise(); | |
const promise2 = somethingElseThatReturnsAPromise(); | |
const promise3 = yetAnotherCallThatReturnsAPromise(); | |
// We create a wrapper promise for all the them using $q.all which follows Promise.all of taking an array of promises | |
const consolidatedPromise = $q.all([promise1, promise2, promise3]); | |
consolidatedPromise.then(function (promiseValues) { | |
console.log('Promise 1:', promiseValues[0]); // The value from `promise1.then(function(value){})` | |
console.log('Promise 2:', promiseValues[1]); // The value from `promise2.then(function(value){})` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<LocalizationProvider messages={myLocalizationMessages}> | |
<Foo> | |
<h1><LocalizationText key="welcomeMessage" /></h1> | |
</Foo> | |
</LocalizationProvider> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Remove whitespace at the start of each line. | |
* | |
* Based on Twig's Twig_TokenParser_Spaceless class | |
*/ | |
class TwigIndentlessTokenParser extends Twig_TokenParser | |
{ | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
register_post_type( 'custom_post_type_name', array( | |
'capabilities' => array( | |
'create_posts' => false, | |
) | |
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open external links in new windows | |
jQuery(document).ready(function($) { | |
var re = new RegExp( '^([^/]+:)?//([^/]+\\.)?' + window.location.host.replace(/\./g, '\\.') + '/'); | |
$('body').on('click', 'a', function(event) { | |
if(!re.test(this.href)) { | |
window.open(this.href, '_blank'); | |
return false; | |
} | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Retrieve the bare structure of a nav menu instead of the formatted output. | |
* | |
* @param unknown $args - the same arguments you pass into wp_nav_menu (the fallback and output arguments do not apply) | |
*/ | |
function prefix_get_nav_menu( $args=array() ) { | |
$args = wp_parse_args( $args, array() ); | |
$args = apply_filters( 'wp_nav_menu_args', $args ); | |
$args = (object) $args; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function send_extra_media_info( $html, $send_id, $attachment ) { | |
@header( "X-Attachment-ID: " . intval( $send_id ) ); | |
foreach( array('post_title', 'image-size' ) as $key ) { | |
if( array_key_exists($key, $attachment) ) { | |
@header( "X-".$key.": " . str_replace( array( "\r", "\n"), ' ', $attachment[$key] ) ); | |
} | |
} |
NewerOlder